<?php


namespace App\Logic;
class BroadcastLogic{
    public static function getLiveStream($user_id,$num,$type=1){
        //获取过期时间60个1秒是1分钟，60个1分钟是1小时，所以60*60*24=1天的秒数，$num是传的有效天数
        $time = time()+(60*60*24*$num);
        $key = config('live.livekey');
        //return $key;
        //将时间写作16
        $txTime = strtoupper(base_convert($time,10,16));
        //加密
        $teSecret = md5($key.$user_id.$txTime);
        //拼接url
        $extStr = '?'.http_build_query([
                'teSecret'=>$teSecret,
                'txTime'=>$txTime
            ]);
        switch ($type){
            case 1:
                return "webrtc://".config('live.liveurl')."/live/".$user_id . (isset($extStr) ? $extStr : "");
                break;
            case 2:
                return "rtmp://".config('live.liveurl')."/live/".$user_id . (isset($extStr) ? $extStr : "");
                break;
        }
    }
    /**
    * config直播配置
    * @name lzh
    * @var string[]
    */
    private static $config=[
        'liveurl'=>'bfyz.zhangfei.site' ,//推流域名
        'moveurl'=>'183777.push.tlivecloud.com' ,//播流域名
        'livekey'=> '5d7b9669583b609756256f334290875a' ,//推流key
        'movekey' => 'FnK6dDfEtKJrtBtysp2T'
        ];
}
